open(BUFF,"BRCA_normalized_mrnaSEQv2.txt");
open(WRBUFF,">BRCA_normalized_mrnaSEQv2_tumor_normal_only.txt");
$line=<BUFF>;
#print $line."\n";
@samples=split("\t",$line);
@tumor_normals;
push(@tumor_normals,0);
for($i=1;$i<@samples;$i++)
{
	@samp=split('-',$samples[$i]);
	$samp[3] =~ s/A//g;
    $samp[3] =~ s/B//g;
	#die "$samp[3]\n";
	if($samp[3] eq "01" || $samp[3] eq "11")
	{	
		if(exists($hash{"$samp[0]-$samp[1]-$samp[2]"}) && $samp[3] ne $temp{"$samp[0]-$samp[1]-$samp[2]"})
		{
			$hash{"$samp[0]-$samp[1]-$samp[2]"}=2;
		}
		else
		{
			$hash{"$samp[0]-$samp[1]-$samp[2]"}=1;
			$temp{"$samp[0]-$samp[1]-$samp[2]"}=$samp[3];
		}
	}
}
$header="";
for($i=1;$i<@samples;$i++)
{
	@samp=split('-',$samples[$i]);
	#die "$samp[3]\n";
	$samp[3] =~ s/A//g;
	$samp[3] =~ s/B//g;
	if(($hash{"$samp[0]-$samp[1]-$samp[2]"} ==2)  && ($samp[3] eq "01" || $samp[3] eq "11") && !exists($tmp{"$samp[0]-$samp[1]-$samp[2]-$samp[3]"}))
	{
		$num=$i;
		$tmp{"$samp[0]-$samp[1]-$samp[2]-$samp[3]"}=1;
		$header=$header."\t$samples[$i]";
		push(@tumor_normals,$num);
	}
}
$header=~ s/^\t//g;
print WRBUFF $header."\n";
while($line=<BUFF>)
{
	chomp($line);
	@samples=split("\t",$line);
	print WRBUFF $samples[0];
	for($i=1;$i<@tumor_normals;$i++)
	{
		print WRBUFF "\t$samples[$tumor_normals[$i]]";	
	}
	print WRBUFF "\n";
}
